<?php defined('SYSPATH') or die('No direct script access.');
/**
* Module Simple Products
*/
class Module_Products_ProductManage {
	
	private $controller;
	private $ss;
	private $thesystems;
	private $myfunctions;
	private $mydatetime;
	private $message;
	private $arraylist;
	
	static function &factory() {
	   $o = new Module_Products_ProductManage();
	  return $o;	
	}
	
	public function __construct()
	{
		$this->controller  = Request::current()->controller();
		$this->ss          = Session::instance();
		$this->thesystems  = Helper_theSystems::factory();
		$this->myfunctions = Helper_myFunctions::factory();
		$this->mydatetime  = Helper_MyDateTime::factory();
		$this->message     = Language_Message::factory();
		$this->arraylist   = Helper_ArrayList::factory();
	}
	
	public function productmanage($id, $command)
	{
		$check_proddetail = $this->thesystems->system_auth('module_products_detail_type');
		$table = ($check_proddetail == 'skus' ? 'skus' : 'ucts');

		switch ($command)
		{
		case "update":

			$p['price01'] = $_POST['price01'];
			$p['price02'] = $_POST['price02'];
			$p['price03'] = $_POST['price03'];
			$p['price04'] = $_POST['price04'];
			$p['stock']   = $_POST['stock'];

			if($check_proddetail == 'skus') 
			{
			$p['weight']  = $_POST['weight'];
			$p['width']   = $_POST['width'];
			$p['length']  = $_POST['length'];
			$p['depth']   = $_POST['depth'];
			}
			  
		  $query = DB::update('prod'.$table)
			  ->set($p)
			  ->where('id', '=', $id);
		  $result = $query->execute();
			  if ($result == 1) {
					$this->message->store_message('u_success');
					$r = Request::current();
					$r->redirect($this->controller.'/productmanage');
			  } else {
					$this->message->store_message('u_fails');
					$r = Request::current();
					$r->redirect($this->controller.'/productmanage?'.$id);
			  }
			break;
		}


		$productlists = DB::select()
			->from('prod'.$table)
			->execute()
			->as_array();

		$productupdate = DB::select()
			->from('prod'.$table)
			->where('id', '=', $id)
			->limit(1)
			->execute();
		
		//$pagination = Helper_myFunctions::factory()->paginations($count,$rpp);
		
		$content['title']		= 'Products Manage';
		$content['content']	= View::factory('inc/productmanage')
			->set('productlists',$productlists)
			->render();
		
		return $content;
	}



}